﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Atom.DAL;
using Atom.Entity;
using Atom.Utility;
using System.Data;

namespace Atom.BLL
{
    public class C2BLL : BaseBLL
    {
        public List<C2Entity> GetC2Entity(DateTime dtBegin, DateTime dtEnd, string whereFilter)
        {
            List<C2Entity> listC2 = new List<C2Entity>();
            try
            {

                LeaveHosRecordDAL dal = new LeaveHosRecordDAL();


                List<AgeEntity> ageEntitys = MedInfo.GetAgeEntity();//获取年龄实体

                int AgeBegin = 0;
                int AgeEnd = 200;

                DataSet dsTemp = new DataSet();
                C2Entity entity = new C2Entity();

                //获取住院总费用及药品总费用
                dsTemp = dal.GetC1EntityBasic(dtBegin, dtEnd, AgeBegin, AgeEnd, string.Empty, Constants.INVOICEITEM_YP);
                entity.TotalFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["TOTALCONSUMEMONEY"]);
                entity.YPFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["INFACTMONEY"]);
                //住院人次数 住院床总数
                entity.InhosCount = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsTemp.Tables[0].Rows[0]["INHOSCOUNT"]);
                entity.OuthosBedCount = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsTemp.Tables[0].Rows[0]["INHOSDAYS"]);

                //住院检查费用
                dsTemp = dal.GetC1EntityBasic(dtBegin, dtEnd, AgeBegin, AgeEnd, string.Empty, Constants.INVOICEITEM_JC);
                entity.ZLFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["INFACTMONEY"]);

                //获取补偿农民（新农合）住院总费用  药品费用
                dsTemp = dal.GetC1EntityBasic(dtBegin, dtEnd, AgeBegin, AgeEnd, Constants.FEETYPE_NH, Constants.INVOICEITEM_YP);
                entity.CHNMTotalFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["TOTALCONSUMEMONEY"]);
                entity.CHNMYPFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["INFACTMONEY"]);

                //获取补偿农民（新农合）住院总费用  检查费用
                dsTemp = dal.GetC1EntityBasic(dtBegin, dtEnd, AgeBegin, AgeEnd, Constants.FEETYPE_NH, Constants.INVOICEITEM_JC);
                entity.CHNMZLFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["INFACTMONEY"]);



                //获取补偿范围总费用，
                dsTemp = dal.GetC1EntityTotalFee(dtBegin, dtEnd, AgeBegin, AgeEnd, Constants.FEETYPE_NH);
                entity.CHNMBCFWTotalFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["DISCOUNTPAY"]);

                //获取补偿范围药品费用
                dsTemp = dal.GetC1EntityDetail(dtBegin, dtEnd, AgeBegin, AgeEnd, Constants.FEETYPE_NH, Constants.SUMMARY_YP);
               
                entity.CHNMBCFWYPFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["INFACTMONEY"]);

                //获取补偿范围总费用，检查费用
                dsTemp = dal.GetC1EntityDetail(dtBegin, dtEnd, AgeBegin, AgeEnd, Constants.FEETYPE_NH, Constants.SUMMARY_JC);
                entity.CHNMBCFWZLFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["INFACTMONEY"]);

                //补偿人次数
                dsTemp = dal.GetC2EntityBCCount(dtBegin, dtEnd, string.Empty);
                entity.InhosBCCount = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsTemp.Tables[0].Rows[0]["INHOSID"]);



                //----------------------------未确定----------------------------------------


                //新农合补偿总额
                entity.XNHBCTotalFee = 0;


                //-------------------------------------------------------------------------





                //门诊总费用
                dsTemp = dal.GetC2EntityDetail(dtBegin, dtEnd, string.Empty, string.Empty);
                entity.ClincTotalFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["MONEY"]); ;
                //门诊人次数
                entity.ClincCount = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["DIAGNOSEID"]); ;
                //门诊补偿额
                entity.ClincBCFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["DISCOUNTDEFRAY"]); ;


                //门诊总费用 药品
                dsTemp = dal.GetC2EntityDetail(dtBegin, dtEnd, Constants.ITEM_YP, string.Empty);
                entity.ClincYPFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsTemp.Tables[0].Rows[0]["MONEY"]); ;

                listC2.Add(entity);




            }
            catch (Exception ex)
            {

                log.Error("C2BLL-->" + ex.Message);
            }

            return listC2;
        }


    }
}
